<%--
  Created by IntelliJ IDEA.
  User: 杨威
  Date: 2021/9/23
  Time: 7:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<input id="stuName" type="text"/><br/>
<input id="stuAge" type="text"/>
<button onclick="m()">提交</button>
<script type="text/javascript">
    var stuName = document.getElementById("stuName");
    var stuAge = document.getElementById("stuAge");
    function m() {
        var stu={"stuName":stuName.value,"stuAge":stuAge.value}
        var s = JSON.stringify(stu);
        var xhr=new XMLHttpRequest()
        xhr.onreadystatechange=function () {
            if(xhr.readyState==4&xhr.status==200){
                var text = xhr.responseText;
                if(text==1){
                    alert('新增成功')
                }else {
                    alert('新增失败')
                }
            }

        }
        xhr.open("post","insert",true)
        xhr.setRequestHeader("Content-type","application/json;charset=utf-8")
        xhr.send(s)
    }
</script>
</body>
</html>
